package com.example.myfirstapp;



import com.parse.Parse;
import com.parse.ParseObject;

import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    
  
    @Override
	public void onCreate( Bundle savedInstanceState )
	{
		super.onCreate( savedInstanceState );
		
		Parse.initialize(this, "OXu4RYDmSTY6AcDXU3D8s20SZT4dmDtvwIyTW5OV", "9QggACgcfbzyIgL56Z3kjc3xztEU4pW50cfYciRV");
		
	    final ActionBar ab = getActionBar();
	    ab.setNavigationMode( ActionBar.NAVIGATION_MODE_TABS );
	    
	    ab.addTab( 
    		ab.newTab()
		        .setText( R.string.frag_title_signin )
		        .setTabListener( 
		        		new MyTabListener( this, SignInFragment.class.getName()) 
        		) 
		);
	 
	    ab.addTab( 
    		ab.newTab()
		        .setText( R.string.frag_title_signup )
		        .setTabListener( 
		        		new MyTabListener( this, SignUpFragment.class.getName()) 
        		) 
		);
		    
	}
   
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item )
    {
        boolean ret;
        if (item.getItemId() == R.id.menu_settings)
        {
            // Handle Settings
        	Log.i("MainActivity", "clicked settings");
            ret = true;
        } 
        else
        {
            ret = super.onOptionsItemSelected( item );
        }
        return ret;
    }
    

    private class MyTabListener implements ActionBar.TabListener {
        private Fragment mFragment;
    	private final Activity mActivity;
		private final String mFragName;

        public MyTabListener(Activity activity, String fragName) {
			mActivity = activity;
			mFragName = fragName;
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
        	mFragment = Fragment.instantiate( mActivity, mFragName );
			ft.add( android.R.id.content, mFragment );
            
        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            ft.remove(mFragment);
			mFragment = null;

        }

        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            
        }

    }
}
